<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
<link type="text/css" rel="stylesheet" href="<%=contextPath %>/static/bootstrap-fileinput/css/fileinput.css" />
<script type="text/javascript" src="<%=contextPath %>/static/bootstrap-fileinput/js/fileinput.js"></script>
<script type="text/javascript" src="<%=contextPath %>/static/bootstrap-fileinput/js/locales/zh.js"></script>
</head>
<body style="background-color: white;" class="gray-bg">
	<div class="ibox-content">
		<form class="form-horizontal m-t " id="signupForm" method="post" enctype="multipart/form-data">
		    <input type="hidden" name="id" value="${taskManager.id }" /> <!--id  -->
		    <input type="hidden" name="plan" value="${taskManager.plan }" /> <!--进度  -->
			<div class="form-group">
				<label class="col-sm-3 control-label">负责人：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="user1Name" onclick="openTree('user',1);" value="${taskManager.chargeUser.truename }" readonly="readonly" placeholder="请选择负责人"/>
					<input type="hidden" class="form-control" id="user1Id" name="principal" value="${taskManager.principal }"/>
					<p class="help-block" style="color: red;">*必填项，请选择一个系统用户</p>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">开始时间：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control datetime" id="startDate" name="startDate" readonly="readonly" value="${taskManager.startDate }"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">结束时间：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control datetime" id="endDate" name="endDate" readonly="readonly" value="${taskManager.endDate }"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">紧急程度：</label>
				<div class="col-sm-8">
					<select class="form-control" name="urgency">
						<c:forEach items="${fns:getDictList('task_urgency')}"
							var="temp1">
							<option value="${temp1.value }" <c:if test="${taskManager.urgency eq temp1.value }">selected</c:if>>${temp1.valueName }</option>
						</c:forEach>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">企业需求：</label>
				<div class="col-sm-8">
					<input type="text" name="companyPosition" id="demandName" class="form-control" placeholder="请选择企业需求"  onclick="chooseDemand()" readonly="readonly" value="${taskManager.companyPosition }"/>
				    <input type="hidden" name="demand.id" id="demandId" class="form-control" value="${taskManager.demand.id }"/>
				    <p class="help-block" style="color: red;">*必填项，请选择一条企业需求</p>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">任务详情：</label>
				<div class="col-sm-8">
					<textarea class="form-control" id="details" name="details" rows="2" cols="2">${taskManager.details}</textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">参与人员：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="user2Name" onclick="openTree('user',2);" readonly="readonly" placeholder="请选择参与人员" value="${taskManager.userNames }"/>
					<input type="hidden" class="form-control" id="user2Id" name="participant" value="${taskManager.participant}"/>
					<p class="help-block" style="color: red;">*必填项，请选择系统用户</p>
				</div>
			</div>
			<!-- <div class="form-group">
				<label class="col-sm-3 control-label">附件：</label>
				<div class="col-sm-8">
					<input type="hidden" id="fileNames1" name="fileNames" />
					<input type="file" name="file" id="fileNames" multiple>
					<p class="help-block"><i class="icon-info-sign"></i>支持图片及文件上传，最大数量5个，文件大小不能超过5M</p>
				</div>
			</div> -->
			<div class="form-group">
				<label class="col-sm-3 control-label"> 备注 ：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="remark" name="remark" value="${taskManager.remark}"/>
				</div>
			</div>
			<div class="form-group" style="text-align: center;">
				<div class="col-sm-12">
					<button class="btn btn-primary" type="button" id="sub">提交</button>
				</div>
			</div>
		</form>
	</div>


	<script>
    $(function () {
    	//日期插件
    	$('#startDate').datetimepicker({
            format: 'yyyy-mm-dd hh:ii:ss',
	        autoclose: true,
	        todayBtn: true,
	        startView: 'day',
	        minView:'day',
	        maxView:'decade',
	        language:  'zh-CN',
	        initialDate : new Date()
	  });
      $('#endDate').datetimepicker({
          format: 'yyyy-mm-dd hh:ii:ss',
	        autoclose: true,
	        todayBtn: true,
	        startView: 'day',
	        minView:'day',
	        maxView:'decade',
	        language:  'zh-CN',
	        startDate: new Date()
	  });
    	initFileInput("fileNames");
        $("#sub").click(function () {
        	//批量验证表单非空
			//调用方式
        	var arr=new Array(
        	  new Array('principal','负责人未填写!'),
        	  new Array('startDate','开始时间未填写!'),
        	  new Array('endDate','结束时间未填写!'),
        	  new Array('urgency','紧急程度未填写!'),
        	  new Array('demandName','企业需求未选择!'),
        	  new Array('details','任务详情未填写!'),
        	  new Array('participant','参与人员未填写!')
        	)
       	    for(var i=0;i<arr.length;i++){
        	    if($("#"+arr[i][0]).val()==''){
        		    $("#"+arr[i][0]).tips({
	  					side:3,
	  		            msg:arr[i][1],
	  		            bg:'#AE81FF',
	  		            time:1
  		            });
        		    $("#"+arr[i][0]).focus();
  				    return;
  			    }
       	    }
        	var beginDate=$("#startDate").val();    
        	var endDate=$("#endDate").val();    
        	var d1 = new Date(beginDate.replace(/\-/g, "\/"));    
        	var d2 = new Date(endDate.replace(/\-/g, "\/")); 
        	if(beginDate!=""&&endDate!=""&&d1 >=d2) {    
        		swal({
        			title:"开始时间不能等于或大于结束时间！",
        			text: "1秒后自动关闭。", 
  	    			timer: 1000, 
  				    showConfirmButton: false
        		});  
        	    return false;    
        	}
            $("#signupForm").ajaxSubmit({
                url: '<%=contextPath%>/taskManager/update',
					type : 'post',
					dataType : "json",
					success : function(data) {
						if (data.code == 200) {
							swal({
								title : data.message,
								type : "success",
								showCancelButton : false,
								confirmButtonText : "确定",
								animation : "slide-from-bottom",
								closeOnConfirm : true
							}, function() {
								top.Dialog.close();
							});
						} else {
							swal("错误", data.message, "error");
						}
					}
				});

			});
		});
    function initFileInput(ctrlName) {
        var control = $('#' + ctrlName);
        var picUrl = '${taskManager.fileNames}';
        var picArr = new Array(); 
    	var picview = new Array(); 
    	picArr = picUrl.split(","); 
    	for(var i = 0;i<picArr.length;i++){
    		var temppic = picArr[i];
    		if(temppic!=""){
        		picview[i] = '<img src="'+temppic+'" class="file-preview-image" style="max-width:100%;max-height:100%">';
    		}
    	} 
        control.fileinput({
        language : 'zh',
        uploadUrl : "<%=contextPath%>/upload/insert",
        uploadAsync: true, //默认异步上传
        showUpload: false, //是否显示上传按钮
        showRemove : false, //显示移除按钮
        showPreview : true, //是否显示预览
        showCaption: false,//是否显示标题
        browseClass: "btn btn-primary", //按钮样式
        dropZoneEnabled: false,//是否显示拖拽区域
        maxFileSize : 5000,
        maxFileCount: 5, //表示允许同时上传的最大文件个数
        enctype: 'multipart/form-data',
        validateInitialCount:true,
        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
    }).on('filebatchselected', function (event, files) {//选中文件事件  
        $(this).fileinput("upload");  
    }).on("fileuploaded", function(e, data) {
        var res = data.response;
        var num=1;
        $('#' + ctrlName+num).attr("value", res.success);
    })
    }
    //分配资源
	function openTree(obj,num){
	     var ids = $("#"+obj+num+"Id").val();
	     var type="";
	     if(num==1){
	    	 type = "redio";
	     }
	   	 var diag = new top.Dialog();
		 diag.Drag=true;
		 diag.Title ="请选择";
		 diag.URL = '<%=contextPath %>/'+obj+'/openZtree?ids='+ids+'&types='+type;
		 diag.Width = 250;
		 diag.Height = 400;
		 diag.CancelEvent = function(){ //关闭事件
			 var tempid = diag.innerFrame.contentWindow.document.getElementById('tempids').value;
			 var tempname = diag.innerFrame.contentWindow.document.getElementById('tempnames').value;
			if(tempid.length!==0){
				if(typeof(num)=="undefined"){ 
					$("#"+obj+"Id").val(tempid);
					$("#"+obj+"Name").val(tempname);
				}else{
					$("#"+obj+num+"Id").val(tempid);
					$("#"+obj+num+"Name").val(tempname);
				}
			}
			diag.close();
		 };
		 diag.show();
	}
	function chooseDemand(){
		 var position = $("#demandName").val();
		 var demandId = $("#demandId").val();
	   	 var diag = new top.Dialog();
		 diag.Drag=true;
		 diag.Title ="请选择企业需求";
		 diag.URL = '<%=contextPath %>/demandEnterprise/chooseDemand?position='+position+'&demandId='+demandId;
		 diag.Width = 700;
		 diag.Height = 650;
		 diag.CancelEvent = function(){ //关闭事件
			 var tempid = diag.innerFrame.contentWindow.document.getElementById('tempids').value;
			 var tempname = diag.innerFrame.contentWindow.document.getElementById('tempnames').value;
			if(tempid.length!==0){
					$("#demandId").val(tempid);
					$("#demandName").val(tempname);
			} 
			diag.close();
		 };
		 diag.show();
	}
	</script>
</body>
</html>